{php $newUI = true;}
{template 'common/header'}
<link href="./resource/css/app.css" rel="stylesheet">
<ul class="nav nav-tabs">
	<li class="{if $_GPC['status'] == 'normal' || $_GPC['status'] == ''}active{/if}"><a href="{php echo url('platform/menu/display', array('status' => 'normal'));}">自定义菜单</a></li>
	<li class="{if $_GPC['status'] == 'history'}active{/if}"><a href="{php echo url('platform/menu/display', array('status' => 'history'));}">历史菜单</a></li>
</ul>
{if $do == 'display'}
{if empty($data) && $_GPC['status'] == 'history'}
<div class="alert alert-info">没有历史菜单</div>
{else}
<div class="clearfix" ng-controller="menuDisplay">
	{if $_GPC['status'] != 'history'}
	<div style="margin-bottom:20px">
		{if empty($default_menu)}
			<a href="{php echo url('platform/menu/add', array('type' => 1));}" class="btn btn-primary"><i class="fa fa-plus"></i> 添加默认菜单</a>
			<a href="javascript:;" onclick="util.message('添加个性化菜单前请先添加默认菜单');" class="btn btn-primary"><i class="fa fa-plus"></i> 添加个性化菜单</a>
		{else}
			<a href="{php echo url('platform/menu/add', array('type' => 3));}" class="btn btn-primary"><i class="fa fa-plus"></i> 添加个性化菜单</a>
		{/if}
	</div>
	{/if}
	<div class="panel panel-default">
		<div class="panel-body table-responsive">
			<table class="table table-hover">
				<thead class="navbar-inner">
				<tr>
					<th>菜单组名</th>
					<th>类型</th>
					<th>显示对象</th>
					<th>是否生效</th>
					<th style="min-width:70px; width:350px" class="text-left">操作</th>
				</tr>
				</thead>
				{loop $data $da}
				<tr>
					<td>
						{if empty($da['title'])}
							{if $da['type'] == 1}
								默认菜单
							{elseif $da['type'] == 2}
								默认菜单(历史记录)
							{else}
								个性化菜单
							{/if}
						{else}
							{$da['title']}
						{/if}
					</td>
					<td>
						{if $da['type'] == 1}
							<span class="label label-success">默认菜单</span>
						{elseif $da['type'] == 2}
							<span class="label label-warning">默认菜单(历史记录)</span>
						{else}
							<span class="label label-danger">个性化菜单</span>
						{/if}
					</td>
					<td>
						{if $da['type'] == 3}
							{if $da['sex'] > 0}性别:{$names['sex'][$da['sex']]} <br>{/if}
							{if $da['group_id'] != -1}粉丝分组:{if $da['group_id'] == -1}不限{else}{$groups[$da['group_id']]['name']}{/if}<br>{/if}
							{if $da['client_platform_type'] > 0}客户端:{$names['client_platform_type'][$da['client_platform_type']]} <br>{/if}
							{if !empty($da['area'])}地区:{$da['area']}{/if}
						{else}
							所有粉丝
						{/if}
					</td>
					<td>
						<input type="checkbox" data-id="{$da['id']}" name="flag" value="0" {if intval($da['status']) == 1} checked="checked" {/if}/>
					</td>
					<td align="left">
						{if $_GPC['status'] == 'history'}
						<a href="{php echo url('platform/menu/remove', array('id' => $da['id'], 'type'=> $da['type'], 'op' => 'recover'));}">恢复</a>
						{/if}
						{if $da['type'] == 1}
							<a href="{php echo url('platform/menu/add', array('id' => $da['id'], 'type'=> 1));}" >编辑</a>
						{else}
							<a href="{php echo url('platform/menu/add', array('id' => $da['id'], 'type'=> $da['type']));}">查看</a>
						{/if}
						{if $da['type'] == 3}
							{if $_GPC['status'] != 'history'}
							<a href="{php echo url('platform/menu/copy', array('id' => $da['id']));}" onclick="if(!confirm('确定复制吗')) return false;">复制编辑</a>
							{/if}
						{/if}
						{if $da['type'] != 1}
						<a href="{php echo url('platform/menu/remove', array('id' => $da['id'], 'status' => $_GPC['status']));}" onclick="if(!confirm('{if $da['type'] == 1}删除默认菜单会清空所有菜单记录，确定吗？{else}确定删除菜单?{/if}')) return false;">删除</a>
						{/if}
					</td>
				</tr>
				{/loop}
			</table>
		</div>
	</div>
</div>
{/if}
<script>
	// $(function(){
	// 	var push_url = "{php echo url('platform/menu/push')}";
	// 	angular.module('menuApp').value('config', {
	// 		'push_url' : push_url,
	// 	});
	// 	angular.bootstrap(document, ['menuApp']);
	// });
</script>
{/if}

{if $do == 'add'}
<div class="conditionMenu" ng-controller="conditionMenuDesigner" id="conditionMenuDesigner" ng-cloak>
	<div class="clearfix form-horizontal">
		<div class="form-group">
			<label class="control-label col-xs-1">菜单组名称</label>
			<div class="col-xs-6">
				<input type="text" class="form-control ng-pristine ng-untouched ng-valid ng-not-empty" ng-model="context.group.title" ng-disabled="context.group.disabled">
				<span class="help-block">给自定义菜单起名便于查找</span>
			</div>
		</div>
		{if $type == 3}
		<div class="form-group">
			<label class="control-label col-xs-1">菜单显示对象</label>
			<div class="col-xs-11">
				<div class="col-xs-2">
					<select ng-model="context.group.matchrule.sex" class="form-control" ng-disabled="context.group.disabled">
						<option value="" ng-disabled="context.group.disabled">性别不限</option>
						<option value="1" ng-disabled="context.group.disabled">男</option>
						<option value="2" ng-disabled="context.group.disabled">女</option>
					</select>
				</div>
				<div class="col-xs-2">
					<select ng-model="context.group.matchrule.group_id" class="form-control" ng-disabled="context.group.disabled">
						<option name="group" value="" ng-disabled="context.group.disabled">粉丝分组不限</option>
						{loop $groups $group}
						<option value="{$group['id']}" ng-disabled="context.group.disabled">{$group['name']}</option>
						{/loop}
					</select>
				</div>
				<div class="col-xs-2">
					<select ng-model="context.group.matchrule.client_platform_type" class="form-control" ng-disabled="context.group.disabled">
						<option value="" ng-disabled="context.group.disabled">手机系统不限</option>
						<option value="1" ng-disabled="context.group.disabled">IOS(苹果)</option>
						<option value="2" ng-disabled="context.group.disabled">Android(安卓)</option>
						<option value="3" ng-disabled="context.group.disabled">Others(其他)</option>
					</select>
				</div>
				<div class="col-xs-2">
					<select ng-model="context.group.matchrule.language" class="form-control" ng-disabled="context.group.disabled">
						<option ng-model="context.group.matchrule.client_platform_type" value="" ng-disabled="context.group.disabled">语言不限</option>
						{loop $languages $lan}
							{if !empty($menu['data']['matchrule']['language'])}
							<option value="{$lan['en']}" selected="{$lan['en'] == $menu['data']['matchrule']['language']}" disabled>{$lan[ch]}</option>
							{else}
							<option value="{$lan['en']}">{$lan['ch']}</option>
							{/if}
						{/loop}
					</select>
				</div>
				<div class="col-xs-2 tpl-district-container">
					<select name="" data-value="{$menu['data']['matchrule']['province']}" ng-model="context.group.matchrule.province" ng-disabled="context.group.disabled" class="form-control tpl-province">
					</select>
					<select name="" data-value="{$menu['data']['matchrule']['city']}" ng-model="context.group.matchrule.city" ng-disabled="context.group.disabled" class="form-control tpl-city">
					</select>
				</div>
			<span class="help-block">根据条件对显示对象进行筛选</span>
			</div>
		</div>
		<div class="alert alert-danger" style="background:#ebccd1">
			<i class="fa fa-info-circle"></i> 个性化菜单一旦上架提交后,将不可更改.如果您不需要某个菜单,您可以删除该菜单后重新设置新菜单.<br>
		</div>
		{/if}
	</div>
	<div class="app clearfix">
		<div class="app-preview">
			<div class="app-header"></div>
			<div class="app-content">
				<div class="inner">
					<div class="title">
						<h1><span>{{context.group.type == 3 ? "个性化菜单" : "默认菜单"}}</span></h1>
					</div>
				</div>
				<div class="nav-menu">
					<div class="js-quickmenu nav-menu-wx clearfix" ng-class="{0 : 'has-nav-0', 1 : 'has-nav-1', 2: 'has-nav-2', 3: 'has-nav-3', 4 : 'has-nav-3'}[context.group.button.length + 1]">
						<ul class="nav-group designer-x">
							<li class="nav-group-item js-sortable" ng-repeat="but in context.group.button" ng-class="{0 : '', 1 : 'active'}[context.activeItem == but ? 1 : 0 ]">
								<input type="hidden" data-role="parent" data-hash="{{but.$$hashKey}}"/>
								<a href="javascript:void(0);" title="拖动排序" ng-click="context.editBut('', but);">
									<i class="fa fa-minus-circle" ng-show="but.sub_button.length > 0"></i>
									{{but.name}}
								</a>
								<dl class="designer-y">
									<dd ng-repeat="subBut in but.sub_button"  ng-class="{0 : '', 1 : 'active'}[context.activeItem == subBut ? 1 : 0 ]">
										<input type="hidden" data-role="sub" data-hash="{{subBut.$$hashKey}}"/>
										<a href="javascript:void(0)" ng-click="context.editBut(subBut, but);">{{subBut.name}}</a>
									</dd>
									<dd ng-if="but.sub_button.length < 5" class="js-not-sortable">
										<a href="javascript:void(0)" ng-click="context.addSubBut(but);"><i class="fa fa-plus"></i></a>
									</dd>
								</dl>
							</li>
							<li class="nav-group-item" class="js-not-sortable"ng-if="context.group.button.length < 3" ng-hide="context.group.disabled">
								<a href="javascript:void(0);" ng-click="context.addBut();" class="text-success">
									<i class="fa fa-plus"></i> 添加菜单
								</a>
							</li>
						</ul>
					</div>
				</div>
			</div>
		</div>
		<div class="app-side">
			<div class="menu app-conditionMenu-edit">
				<div class="arrow-left"></div>
				<div class="inner">
					<div class="panel panel-default">
						<div class="panel-body form-horizontal">
							<!-- <div class="conditionMenu-wx">
								<div class="card">
									<div class="nav-region">
										<div class="first-nav">
											<h3>标题</h3>
											<div class="alert">
												<div class="form-group">
													<label class="control-label col-xs-2">标题</label>
													<div class="col-xs-10">
														<input type="text" class="form-control" ng-model="context.group.title" ng-disabled="context.group.disabled"/>
														<span class="help-block">仅用于区分个性化菜单</span>
													</div>
												</div>
											</div>
										</div>
									</div>
								</div>
							</div> -->
							{if $type == 3}
							<!-- <div class="alert alert-danger" style="background:#ebccd1">
								<i class="fa fa-info-circle"></i> 个性化菜单一旦上架提交后,将不可更改.如果您不需要某个菜单,您可以删除该菜单后重新设置新菜单.<br>
							</div>
							<div class="conditionMenu-wx">
								<div class="card">
									<div class="nav-region">
										<div class="first-nav">
											<h3>匹配设置</h3>
											<div class="alert">
												<div class="form-group">
													<label class="control-label col-xs-2">语言限制</label>
													<div class="col-xs-4" style="margin-top:10px">
														<select ng-model="context.group.matchrule.language" class="form-control">
															<option value="" disabled>选择语言</option>
															{loop $languages $lan}
																{if !empty($menu['data']['matchrule']['language'])}
																<option value="{$lan['en']}" selected="{$lan['en'] == $menu['data']['matchrule']['language']}" disabled>{$lan[ch]}</option>
																{else}
																<option value="{$lan['en']}">{$lan['ch']}</option>
																{/if}
															{/loop}
														</select>
													</div>
												</div>
											</div>
										</div>
									</div>
								</div>
							</div> -->
							{/if}
							<div class="card" ng-if="context.group.button.length > 0">
								<div class="btns">
									<a href="javascript:;" ng-click="context.removeBut(context.activeItem, context.activeType)"><i class="fa fa-times"></i></a>
								</div>
								<div class="nav-region">
									<div class="first-nav">
										<h3>菜单设置</h3>
										<div class="alert">
											<div class="form-group">
												<label class="control-label col-xs-2">菜单名称</label>
												<div class="col-xs-10">
													<div class="input-group">
														<input type="text" class="form-control" name="" id="title" ng-model="context.activeItem.name" ng-disabled="context.group.disabled"/>
														<div class="input-group-btn">
															<span class="btn btn-primary" ng-click="context.selectEmoji();" ng-disabled="context.group.disabled"><i class="fa fa-github-alt"></i> 添加表情</span>
														</div>
													</div>
												</div>
											</div>
											<div class="form-group" ng-if="context.activeType == 2 || (context.activeType == 1 && context.activeItem.sub_button.length == 0)">
												<label class="control-label col-xs-2">菜单内容</label>
												<div class="col-xs-10 menu-action">
													<span {if $_W['account']['level'] == '1'}style="display:none;"{/if}>
													<label class="radio-inline">
														<!-- <input type="radio" name="ipt" ng-model="context.activeItem.type" value="media_id" ng-disabled="context.group.disabled"> 发送消息 -->
														<input type="radio" name="ipt" ng-checked="context.activeItem.type == 'media_id' || context.activeItem.type == 'click'" ng-model="context.activeItem.type" value="media_id" ng-disabled="context.group.disabled"> 发送消息
													</label>
													<label class="radio-inline">
														<input type="radio" name="ipt" ng-model="context.activeItem.type" value="view" ng-disabled="context.group.disabled"> 跳转网页
													</label>
													<label class="radio-inline">
														<input type="radio" name="ipt" ng-model="context.activeItem.type" value="scancode_push" ng-disabled="context.group.disabled"> 扫码
													</label>
													<label class="radio-inline">
														<input type="radio" name="ipt" ng-model="context.activeItem.type" value="scancode_waitmsg" ng-disabled="context.group.disabled"> 扫码（等待信息）
													</label>
													<label class="radio-inline">
														<input type="radio" name="ipt" ng-model="context.activeItem.type" value="pic_sysphoto" ng-disabled="context.group.disabled"> 系统拍照发图
													</label>
													<label class="radio-inline">
														<input type="radio" name="ipt" ng-model="context.activeItem.type" value="pic_photo_or_album" ng-disabled="context.group.disabled"> 拍照或者相册发图
													</label>
													<label class="radio-inline">
														<input type="radio" name="ipt" ng-model="context.activeItem.type" value="pic_weixin" ng-disabled="context.group.disabled"> 微信相册发图
													</label>
													<label class="radio-inline">
														<input type="radio" name="ipt" ng-model="context.activeItem.type" value="location_select" ng-disabled="context.group.disabled"> 地理位置
													</label>
													</span>
											<!-- 		<label class="radio-inline">
														<input type="radio" name="ipt" ng-model="context.activeItem.type" value="media_id" ng-disabled="context.group.disabled"> 回复素材
													</label>
													<label class="radio-inline">
														<input type="radio" name="ipt" ng-model="context.activeItem.type" value="view_limited" ng-disabled="context.group.disabled"> 跳转图文
													</label> -->
													<div {if $_W['account']['level'] == '1'}style="display:none;"{/if}ng-show="context.activeItem.type == 'view';">
														<hr />
														<div class="input-group">
															<input class="form-control" id="ipt-url" type="text" ng-model="context.activeItem.url" ng-disabled="context.group.disabled"/>
															<div class="input-group-btn">
																<button class="btn btn-primary" id="search" ng-click="context.select_link()" ng-disabled="context.group.disabled"><i class="fa fa-external-link"></i> 系统链接</button>
															</div>
														</div>
														<span class="help-block">指定点击此菜单时要跳转的链接（注：链接需加http://）</span>
														<span class="help-block"><strong>注意: 由于接口限制. 如果你没有网页oAuth接口权限, 这里输入链接直接进入微站个人中心时将会有缺陷(有可能获得不到当前访问用户的身份信息. 如果没有oAuth接口权限, 建议你使用图文回复的形式来访问个人中心)</strong></span>
													</div>
													<div {if $_W['account']['level'] != '1'}ng-show="context.activeItem.type == 'media_id' || context.activeItem.type == 'view_limited'"{/if}>
														<hr />
														<div class="input-group">
															<ul class="replytype nav nav-pills">
																<li data-type="news"><a href="javascript:;" ng-click="context.select_mediaid('news');">图文</a></li>
																<li data-type="image"><a href="javascript:;" ng-click="context.select_mediaid('image');">图片</a></li>
																<li data-type="voice"><a href="javascript:;" ng-click="context.select_mediaid('voice');">语音</a></li>
																<li data-type="video"><a href="javascript:;" ng-click="context.select_mediaid('video');">视频</a></li>
																<li data-type="keyword"><a href="javascript:;" ng-click="context.select_mediaid('keyword', '1');">触发关键字</a></li>
															</ul>
															<input class="form-control" id="ipt-url" ng-if="context.activeItem.type == 'media_id' && context.activeItem.key == ''" type="text" ng-model="context.activeItem.media_id" ng-disabled="context.group.disabled"/>
															<input class="form-control" id="ipt-forward" ng-if="context.activeItem.type == 'media_id' && context.activeItem.key != ''" type="text" ng-model="context.activeItem.key" ng-disabled="context.group.disabled"/>
														</div>
														<span class="help-block">公众平台的素材id</span>
													</div>
													<div ng-show="context.activeItem.type != 'view' && context.activeItem.type != 'media_id' && context.activeItem.type != 'view_limited'" style="position:relative;">
														<hr />
														<div class="input-group" ng-show="context.activeItem.type == 'location_select'">
															<span class="fa fa-map-marker"></span> 菜单内容为地理位置，那么点击这个菜单是，系统发送当前地理位置
														</div>
														<div class="input-group" ng-show="context.activeItem.type == 'pic_sysphoto' || context.activeItem.type == 'pic_photo_or_album'">
															<span class="fa fa-camera"></span> 菜单内容为系统拍照发图/拍照或者相册发图，那么点击这个菜单是，系统拍照
														</div>
														<div class="input-group" ng-show="context.activeItem.type == 'pic_weixin'">
															<span class="fa fa-money"></span> 菜单内容为微信相册发图，那么点击这个菜单是，选择图片发送
														</div>
														<div class="input-group" ng-show="context.activeItem.type == 'scancode_push' || context.activeItem.type == 'scancode_waitmsg'">
															<span class="fa fa-qrcode"></span> 菜单内容为扫码，那么点击这个菜单是，手机扫描二维码
														</div>
														<div class="input-group">
															<input class="form-control" id="ipt-forward" type="text" ng-model="context.activeItem.key" ng-disabled="context.group.disabled"/>
															<div class="input-group-btn">
																<button class="btn btn-primary" id="search" ng-click="context.select_mediaid('keyword', '2')" ng-disabled="context.group.disabled"><i class="fa fa-search"></i> 搜索</button>
															</div>
														</div>
														<div id="key-result" style="width:100%;position:absolute;top:55px;left:0px;display:none;z-index:10000">
															<ul class="dropdown-menu" style="display:block;width:88%;"></ul>
														</div>
														<span class="help-block">指定点击此菜单时要执行的操作, 你可以在这里输入关键字, 那么点击这个菜单时就就相当于发送这个内容至微擎系统</span>
														<span class="help-block"><strong>这个过程是程序模拟的, 比如这里添加关键字: 优惠券, 那么点击这个菜单是, 微擎系统相当于接受了粉丝用户的消息, 内容为"优惠券"</strong></span>
													</div>
												</div>
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	{if $menu['type'] == 1 || (!$id) || !$menu['status']}
		<div class="shop-preview col-xs-12 col-sm-9 col-lg-10">
			<div class="text-center alert alert-warning" style="background:#faebcc">
				{if !$id}
					<span class="btn btn-primary" id="btn-submit" ng-click="context.submit();">上架</span>
				{else}
					<span class="btn btn-primary" id="btn-submit" ng-click="context.group.button.length > 0 ? context.submit() : context.remove()">{{context.group.button.length > 0 ? '上架' : '删除默认菜单'}}</span>
				{/if}
			</div>
		</div>
	{/if}
	</div>
</div>
{/if}

<script type="text/javascript">
$(function(){
	var push_url = "{php echo url('platform/menu/push')}";
	type = "{$type}";
	group = {php echo !empty($params) ? json_encode($params) : "null"};
	id = "{$id}";
	status = "{$params['status']}";
	remove_url = "{php echo url('platform/menu/remove', array('id' => $id));}";
	success_url = "{php echo url('platform/menu/display');}";
	site_url = "{$_W['siteroot']}";
	search_key_url = "{php echo url('platform/menu/search_key')}";
	angular.module('menuApp').value('config', {
		'id' : id,
		'status' : status,
		'group' : group,
		'type' : type,
		'remove_url' : remove_url,
		'success_url' : success_url,
		'site_url' : site_url,
		'search_key_url' : search_key_url,
		'push_url' : push_url
	});
	angular.bootstrap(document, ['menuApp']);
});
</script>
{template 'common/footer'}